package com.jmz.apt.api.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.*;
import com.jmz.apt.api.message.request.RequestMessageTemplate;
import com.jmz.apt.api.message.response.ResponseMessageTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.List;

/**
 * @Description : {   }
 * @Author : create by NanFeng on 2019-11-06 14:14
 */
public class BaseController {

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    @Autowired
    protected HttpSession session;

    @Autowired
    protected ResponseMessageTemplate responseMessageTemplate;

    @Autowired
    protected StringRedisTemplate stringRedisTemplate;

    @Autowired
    protected RedisTemplate<String, Serializable> redisTemplate;

    @Autowired
    protected ObjectMapper objectMapper;

    protected void getPage(RequestMessageTemplate reqt) {
        //页号，默认0
        int pageNo = 1;
        if (reqt.getQuery().getPageno() != null) {
            pageNo = reqt.getQuery().getPageno();
        }
        //页数，默认1000
        int pageSize = 20;
        if (reqt.getQuery().getPagesize() != null) {
            pageSize = reqt.getQuery().getPagesize();
        }
        PageHelper.startPage(pageNo, pageSize);
    }

    protected <T> PageInfo<T> pageInfo(List<T> list) {
        PageInfo<T> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
